/*
   自动匹配ajax中使用get还是post方式
 */
function ajaxAll(url,data,method,success) {
    var ajax = new XMLHttpRequest();

    if(method=='get') {
        if(data) {
            ajax.open('get',url+'?'+data);
        }else {
            ajax.open('get',url);
        }
        ajax.send();
    }else {
        ajax.open('post',url);
        if(data) {
            ajax.setRequestHeader("Content-type","application/x-www-form-urlencoded");
            ajax.send(data);
        }else {
            ajax.send();
        }
    }

    ajax.onreadystatechange = function () {
        if(ajax.readyState == 4 && ajax.status == 200) {
            console.log(ajax.responseText);
            success(ajax.responseText);
        };
    };

}